home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9207.ZIP
/
DFLAT.792
< prev
next >
Wrap
Text File
|
1992-05-26
|
26KB
|
842 lines
_C PROGRAMMING COLUMN_
by Al Stevens
[LISTING ONE]
/* ----------- box.c ------------ */
#include "dflat.h"
int BoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
case PAINT:
return FALSE;
case LEFT_BUTTON:
case BUTTON_RELEASED:
return SendMessage(GetParent(wnd), msg, p1, p2);
case BORDER:
rtn = BaseWndProc(BOX, wnd, msg, p1, p2);
if (ct != NULL)
if (ct->itext != NULL)
writeline(wnd, ct->itext, 1, 0, FALSE);
return rtn;
default:
break;
}
}
return BaseWndProc(BOX, wnd, msg, p1, p2);
}
[LISTING TWO]
/* -------------- button.c -------------- */
#include "dflat.h"
void PaintMsg(WINDOW wnd, CTLWINDOW *ct, RECT *rc)
{
if (isVisible(wnd)) {
if (TestAttribute(wnd, SHADOW) && cfg.mono == 0) {
/* -------- draw the button's shadow ------- */
int x;
background = WndBackground(GetParent(wnd));
foreground = BLACK;
for (x = 1; x <= WindowWidth(wnd); x++)
wputch(wnd, 223, x, 1);
wputch(wnd, 220, WindowWidth(wnd), 0);
}
if (ct->itext != NULL) {
unsigned char *txt;
txt = DFcalloc(1, strlen(ct->itext)+10);
if (ct->setting == OFF) {
txt[0] = CHANGECOLOR;
txt[1] = wnd->WindowColors
[HILITE_COLOR] [FG] | 0x80;
txt[2] = wnd->WindowColors
[STD_COLOR] [BG] | 0x80;
}
CopyCommand(txt+strlen(txt),ct->itext,!ct->setting,
WndBackground(wnd));
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) txt, 0);
free(txt);
}
/* --------- write the button's text ------- */
WriteTextLine(wnd, rc, 0, wnd == inFocus);
}
}
void LeftButtonMsg(WINDOW wnd, MESSAGE msg, CTLWINDOW *ct)
{
if (cfg.mono == 0) {
/* --------- draw a pushed button -------- */
int x;
background = WndBackground(GetParent(wnd));
foreground = WndBackground(wnd);
wputch(wnd, ' ', 0, 0);
for (x = 0; x < WindowWidth(wnd); x++) {
wputch(wnd, 220, x+1, 0);
wputch(wnd, 223, x+1, 1);
}
}
if (msg == LEFT_BUTTON)
SendMessage(NULL, WAITMOUSE, 0, 0);
else
SendMessage(NULL, WAITKEYBOARD, 0, 0);
SendMessage(wnd, PAINT, 0, 0);
if (ct->setting == ON)
PostMessage(GetParent(wnd), COMMAND, ct->command, 0);
else
beep();
}
int ButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
BaseWndProc(BUTTON, wnd, msg, p1, p2);
p1 = 0;
/* ------- fall through ------- */
case PAINT:
PaintMsg(wnd, ct, (RECT*)p1);
return TRUE;
case KEYBOARD:
if (p1 != '\r')
break;
/* ---- fall through ---- */
case LEFT_BUTTON:
LeftButtonMsg(wnd, msg, ct);
return TRUE;
case HORIZSCROLL:
return TRUE;
default:
break;
}
}
return BaseWndProc(BUTTON, wnd, msg, p1, p2);
}
[LISTING THREE]
/* -------------- checkbox.c ------------ */
#include "dflat.h"
int CheckBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
case MOVE:
rtn = BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
SetFocusCursor(wnd);
return rtn;
case PAINT: {
char cb[] = "[ ]";
if (ct->setting)
cb[1] = 'X';
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) cb, 0);
SetFocusCursor(wnd);
break;
}
case KEYBOARD:
if ((int)p1 != ' ')
break;
case LEFT_BUTTON:
ct->setting ^= ON;
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
default:
break;
}
}
return BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
}
BOOL CheckBoxSetting(DBOX *db, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(db, cmd, CHECKBOX);
if (ct != NULL)
return (ct->isetting == ON);
return FALSE;
}
[LISTING FOUR]
/* -------------- combobox.c -------------- */
#include "dflat.h"
int ListProc(WINDOW, MESSAGE, PARAM, PARAM);
int ComboProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
wnd->extension = CreateWindow(
LISTBOX,
NULL,
wnd->rc.lf,wnd->rc.tp+1,
wnd->ht-1, wnd->wd+1,
NULL,
GetParent(wnd),
ListProc,
HASBORDER | NOCLIP | SAVESELF);
((WINDOW)(wnd->extension))->ct->command =
wnd->ct->command;
wnd->ht = 1;
wnd->rc.bt = wnd->rc.tp;
break;
case PAINT:
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
wputch(wnd, DOWNSCROLLBOX, WindowWidth(wnd), 0);
break;
case KEYBOARD:
if ((int)p1 == DN) {
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
return TRUE;
}
break;
case LEFT_BUTTON:
if ((int)p1 == GetRight(wnd) + 1)
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
break;
case CLOSE_WINDOW:
SendMessage(wnd->extension, CLOSE_WINDOW, 0, 0);
break;
default:
break;
}
return BaseWndProc(COMBOBOX, wnd, msg, p1, p2);
}
int ListProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
DBOX *db = GetParent(wnd)->extension;
WINDOW cwnd = ControlWindow(db, wnd->ct->command);
char text[130];
int rtn;
WINDOW currFocus;
switch (msg) {
case CREATE_WINDOW:
wnd->ct = DFmalloc(sizeof(CTLWINDOW));
wnd->ct->setting = OFF;
break;
case SETFOCUS:
if ((int)p1 == FALSE) {
SendMessage(wnd, HIDE_WINDOW, 0, 0);
wnd->ct->setting = OFF;
}
else
wnd->ct->setting = ON;
break;
case SHOW_WINDOW:
if (wnd->ct->setting == OFF)
return TRUE;
break;
case BORDER:
currFocus = inFocus;
inFocus = NULL;
rtn = DefaultWndProc(wnd, msg, p1, p2);
inFocus = currFocus;
return rtn;
case LB_SELECTION:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, LB_GETTEXT,
(PARAM) text, wnd->selection);
PutItemText(GetParent(wnd), wnd->ct->command, text);
SendMessage(cwnd, PAINT, 0, 0);
cwnd->TextChanged = TRUE;
return rtn;
case KEYBOARD:
switch ((int) p1) {
case ESC:
case FWD:
case BS:
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
default:
break;
}
break;
case LB_CHOOSE:
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
case CLOSE_WINDOW:
if (wnd->ct != NULL)
free(wnd->ct);
wnd->ct = NULL;
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
void PutComboListText(WINDOW wnd, enum commands cmd, char *text)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, COMBOBOX);
if (ct != NULL) {
WINDOW lwnd = ((WINDOW)(ct->wnd))->extension;
SendMessage(lwnd, ADDTEXT, (PARAM) text, 0);
}
}
[LISTING FIVE]
/* ------------------ msgbox.c ------------------ */
#include "dflat.h"
extern DBOX MsgBox;
extern DBOX InputBoxDB;
WINDOW CancelWnd;
static int ReturnValue;
int MessageBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
GetClass(wnd) = MESSAGEBOX;
ClearAttribute(wnd, CONTROLBOX);
break;
case KEYBOARD:
if (p1 == '\r' || p1 == ESC)
ReturnValue = (int)p1;
break;
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
int YesNoBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
GetClass(wnd) = MESSAGEBOX;
ClearAttribute(wnd, CONTROLBOX);
break;
case KEYBOARD: {
int c = tolower((int)p1);
if (c == 'y')
SendMessage(wnd, COMMAND, ID_OK, 0);
else if (c == 'n')
SendMessage(wnd, COMMAND, ID_CANCEL, 0);
break;
}
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
int ErrorBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
GetClass(wnd) = ERRORBOX;
break;
case KEYBOARD:
if (p1 == '\r' || p1 == ESC)
ReturnValue = (int)p1;
break;
default:
break;
}
return BaseWndProc(ERRORBOX, wnd, msg, p1, p2);
}
int CancelBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
CancelWnd = wnd;
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
break;
case COMMAND:
if ((int) p1 == ID_CANCEL && (int) p2 == 0)
SendMessage(GetParent(wnd), msg, p1, p2);
return TRUE;
case CLOSE_WINDOW:
CancelWnd = NULL;
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
p1 = TRUE;
break;
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
void CloseCancelBox(void)
{
if (CancelWnd != NULL)
SendMessage(CancelWnd, CLOSE_WINDOW, 0, 0);
}
static char *InputText;
static int TextLength;
int InputBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
switch (msg) {
case CREATE_WINDOW:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(ControlWindow(&InputBoxDB,ID_INPUTTEXT),
SETTEXTLENGTH, TextLength, 0);
return rtn;
case COMMAND:
if ((int) p1 == ID_OK && (int) p2 == 0)
GetItemText(wnd, ID_INPUTTEXT, InputText, TextLength);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
BOOL InputBox(WINDOW wnd,char *ttl,char *msg,char *text,int len)
{
InputText = text;
TextLength = len;
InputBoxDB.dwnd.title = ttl;
InputBoxDB.dwnd.w = 4 +
max(20, max(len, max(strlen(ttl), strlen(msg))));
InputBoxDB.ctl[1].dwnd.x = (InputBoxDB.dwnd.w-2-len)/2;
InputBoxDB.ctl[0].dwnd.w = strlen(msg);
InputBoxDB.ctl[0].itext = msg;
InputBoxDB.ctl[1].dwnd.w = len;
InputBoxDB.ctl[2].dwnd.x = (InputBoxDB.dwnd.w - 20) / 2;
InputBoxDB.ctl[3].dwnd.x = InputBoxDB.ctl[2].dwnd.x + 10;
InputBoxDB.ctl[2].isetting = ON;
InputBoxDB.ctl[3].isetting = ON;
return DialogBox(wnd, &InputBoxDB, TRUE, InputBoxProc);
}
BOOL GenericMessage(WINDOW wnd,char *ttl,char *msg,int buttonct,
int (*wndproc)(struct window *,enum messages,PARAM,PARAM),
char *b1, char *b2, int c1, int c2, int isModal)
{
BOOL rtn;
MsgBox.dwnd.title = ttl;
MsgBox.ctl[0].dwnd.h = MsgHeight(msg);
MsgBox.ctl[0].dwnd.w = max(max(MsgWidth(msg),
buttonct*8 + buttonct + 2), strlen(ttl)+2);
MsgBox.dwnd.h = MsgBox.ctl[0].dwnd.h+6;
MsgBox.dwnd.w = MsgBox.ctl[0].dwnd.w+4;
if (buttonct == 1)
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 10) / 2;
else {
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 20) / 2;
MsgBox.ctl[2].dwnd.x = MsgBox.ctl[1].dwnd.x + 10;
MsgBox.ctl[2].class = BUTTON;
}
MsgBox.ctl[1].dwnd.y = MsgBox.dwnd.h - 4;
MsgBox.ctl[2].dwnd.y = MsgBox.dwnd.h - 4;
MsgBox.ctl[0].itext = msg;
MsgBox.ctl[1].itext = b1;
MsgBox.ctl[2].itext = b2;
MsgBox.ctl[1].command = c1;
MsgBox.ctl[2].command = c2;
MsgBox.ctl[1].isetting = ON;
MsgBox.ctl[2].isetting = ON;
rtn = DialogBox(wnd, &MsgBox, isModal, wndproc);
MsgBox.ctl[2].class = 0;
return rtn;
}
WINDOW MomentaryMessage(char *msg)
{
WINDOW wnd = CreateWindow(
TEXTBOX,
NULL,
-1,-1,MsgHeight(msg)+2,MsgWidth(msg)+2,
NULL,NULL,NULL,
HASBORDER | SHADOW | SAVESELF);
SendMessage(wnd, SETTEXT, (PARAM) msg, 0);
if (cfg.mono == 0) {
WindowClientColor(wnd, WHITE, GREEN);
WindowFrameColor(wnd, WHITE, GREEN);
}
SendMessage(wnd, SHOW_WINDOW, 0, 0);
return wnd;
}
int MsgHeight(char *msg)
{
int h = 1;
while ((msg = strchr(msg, '\n')) != NULL) {
h++;
msg++;
}
return min(h, SCREENHEIGHT-10);
}
int MsgWidth(char *msg)
{
int w = 0;
char *cp = msg;
while ((cp = strchr(msg, '\n')) != NULL) {
w = max(w, (int) (cp-msg));
msg = cp+1;
}
return min(max(strlen(msg),w), SCREENWIDTH-10);
}
[LISTING SIX]
/* -------- radio.c -------- */
#include "dflat.h"
static CTLWINDOW *rct[MAXRADIOS];
int RadioButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
DBOX *db = GetParent(wnd)->extension;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
case MOVE:
rtn = BaseWndProc(RADIOBUTTON,wnd,msg,p1,p2);
SetFocusCursor(wnd);
return rtn;
case PAINT: {
char rb[] = "( )";
if (ct->setting)
rb[1] = 7;
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) rb, 0);
SetFocusCursor(wnd);
break;
}
case KEYBOARD:
if ((int)p1 != ' ')
break;
case LEFT_BUTTON:
PushRadioButton(db, ct->command);
break;
default:
break;
}
}
return BaseWndProc(RADIOBUTTON, wnd, msg, p1, p2);
}
void PushRadioButton(DBOX *db, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
if (ct != NULL) {
SetRadioButton(db, ct);
ct->isetting = ON;
}
}
void SetRadioButton(DBOX *db, CTLWINDOW *ct)
{
CTLWINDOW *ctt = db->ctl;
int i;
/* --- clear all the radio buttons in this group on the dialog box --- */
/* -------- build a table of all radio buttons at the
same x vector ---------- */
for (i = 0; i < MAXRADIOS; i++)
rct[i] = NULL;
while (ctt->class) {
if (ctt->class == RADIOBUTTON)
if (ct->dwnd.x == ctt->dwnd.x)
rct[ctt->dwnd.y] = ctt;
ctt++;
}
/* ----- find the start of the radiobutton group ---- */
i = ct->dwnd.y;
while (i >= 0 && rct[i] != NULL)
--i;
/* ---- ignore everthing before the group ------ */
while (i >= 0)
rct[i--] = NULL;
/* ----- find the end of the radiobutton group ---- */
i = ct->dwnd.y;
while (i < MAXRADIOS && rct[i] != NULL)
i++;
/* ---- ignore everthing past the group ------ */
while (i < MAXRADIOS)
rct[i++] = NULL;
for (i = 0; i < MAXRADIOS; i++) {
if (rct[i] != NULL) {
int wason = rct[i]->setting;
rct[i]->setting = OFF;
if (wason)
SendMessage(rct[i]->wnd, PAINT, 0, 0);
}
}
ct->setting = ON;
SendMessage(ct->wnd, PAINT, 0, 0);
}
BOOL RadioButtonSetting(DBOX *db, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
if (ct != NULL)
return (ct->setting == ON);
return FALSE;
}
[LISTING SEVEN]
/* ------------- slidebox.c ------------ */
#include "dflat.h"
static int (*GenericProc)
(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2);
static BOOL KeepRunning;
static int SliderLen;
static int Percent;
extern DBOX SliderBoxDB;
static void InsertPercent(char *s)
{
int offset;
char pcc[5];
sprintf(s, "%c%c%c",
CHANGECOLOR,
color[DIALOG][SELECT_COLOR][FG]+0x80,
color[DIALOG][SELECT_COLOR][BG]+0x80);
s += 3;
memset(s, ' ', SliderLen);
*(s+SliderLen) = '\0';
sprintf(pcc, "%d%%", Percent);
strncpy(s+SliderLen/2-1, pcc, strlen(pcc));
offset = (SliderLen * Percent) / 100;
memmove(s+offset+4, s+offset, strlen(s+offset)+1);
sprintf(pcc, "%c%c%c%c",
RESETCOLOR,
CHANGECOLOR,
color[DIALOG][SELECT_COLOR][BG]+0x80,
color[DIALOG][SELECT_COLOR][FG]+0x80);
strncpy(s+offset, pcc, 4);
*(s + strlen(s) - 1) = RESETCOLOR;
}
static int SliderTextProc(
WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
switch (msg) {
case PAINT:
Percent = (int)p2;
InsertPercent(GetText(wnd) ?
GetText(wnd) : SliderBoxDB.ctl[1].itext);
GenericProc(wnd, PAINT, 0, 0);
if (Percent >= 100)
SendMessage(GetParent(wnd),COMMAND,ID_CANCEL,0);
if (!dispatch_message())
PostMessage(GetParent(wnd), ENDDIALOG, 0, 0);
return KeepRunning;
default:
break;
}
return GenericProc(wnd, msg, p1, p2);
}
static int SliderBoxProc(
WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
WINDOW twnd;
switch (msg) {
case CREATE_WINDOW:
AddAttribute(wnd, SAVESELF);
rtn = DefaultWndProc(wnd, msg, p1, p2);
twnd = SliderBoxDB.ctl[1].wnd;
GenericProc = twnd->wndproc;
twnd->wndproc = SliderTextProc;
KeepRunning = TRUE;
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
return rtn;
case COMMAND:
if ((int)p2 == 0 && (int)p1 == ID_CANCEL) {
if (Percent >= 100 ||
YesNoBox("Terminate process?"))
KeepRunning = FALSE;
else
return TRUE;
}
break;
case CLOSE_WINDOW:
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
WINDOW SliderBox(int len, char *ttl, char *msg)
{
SliderLen = len;
SliderBoxDB.dwnd.title = ttl;
SliderBoxDB.dwnd.w =
max(strlen(ttl),max(len, strlen(msg)))+4;
SliderBoxDB.ctl[0].itext = msg;
SliderBoxDB.ctl[0].dwnd.w = strlen(msg);
SliderBoxDB.ctl[0].dwnd.x =
(SliderBoxDB.dwnd.w - strlen(msg)-1) / 2;
SliderBoxDB.ctl[1].itext =
DFrealloc(SliderBoxDB.ctl[1].itext, len+10);
Percent = 0;
InsertPercent(SliderBoxDB.ctl[1].itext);
SliderBoxDB.ctl[1].dwnd.w = len;
SliderBoxDB.ctl[1].dwnd.x = (SliderBoxDB.dwnd.w-len-1)/2;
SliderBoxDB.ctl[2].dwnd.x = (SliderBoxDB.dwnd.w-10)/2;
DialogBox(NULL, &SliderBoxDB, FALSE, SliderBoxProc);
return SliderBoxDB.ctl[1].wnd;
}
[LISTING EIGHT]
/* ------------ spinbutt.c ------------- */
#include "dflat.h"
int SpinButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case CREATE_WINDOW:
wnd->wd -= 2;
wnd->rc.rt -= 2;
break;
case SETFOCUS:
rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
SetFocusCursor(wnd);
return rtn;
case PAINT:
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
wputch(wnd,UPSCROLLBOX,WindowWidth(wnd), 0);
wputch(wnd,DOWNSCROLLBOX,WindowWidth(wnd)+1,0);
SetFocusCursor(wnd);
break;
case LEFT_BUTTON:
if (p1 == GetRight(wnd) + 1)
SendMessage(wnd, KEYBOARD, UP, 0);
else if (p1 == GetRight(wnd) + 2)
SendMessage(wnd, KEYBOARD, DN, 0);
if (wnd != inFocus)
SendMessage(wnd, SETFOCUS, TRUE, 0);
return TRUE;
case LB_SETSELECTION:
rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
wnd->wtop = (int) p1;
SendMessage(wnd, PAINT, 0, 0);
return rtn;
default:
break;
}
}
return BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
}
[LISTING NINE]
/* -------------- text.c -------------- */
#include "dflat.h"
int TextProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int i, len;
CTLWINDOW *ct = GetControl(wnd);
char *cp, *cp2 = ct->itext;
switch (msg) {
case PAINT:
if (ct == NULL ||
ct->itext == NULL ||
GetText(wnd) != NULL)
break;
len = min(ct->dwnd.h, MsgHeight(cp2));
cp = cp2;
for (i = 0; i < len; i++) {
int mlen;
char *txt = cp;
char *cp1 = cp;
char *np = strchr(cp, '\n');
if (np != NULL)
*np = '\0';
mlen = strlen(cp);
while ((cp1=strchr(cp1,SHORTCUTCHAR)) != NULL) {
mlen += 3;
cp1++;
}
if (np != NULL)
*np = '\n';
txt = DFmalloc(mlen+1);
CopyCommand(txt, cp, FALSE, WndBackground(wnd));
txt[mlen] = '\0';
SendMessage(wnd, ADDTEXT, (PARAM)txt, 0);
if ((cp = strchr(cp, '\n')) != NULL)
cp++;
free(txt);
}
break;
default:
break;
}
return BaseWndProc(TEXT, wnd, msg, p1, p2);
}
[LISTING TEN]
/* ----------- watch.c ----------- */
#include "dflat.h"
static int WatchIconProc(
WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
switch (msg) {
case CREATE_WINDOW:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, HIDE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
return rtn;
case PAINT:
SetStandardColor(wnd);
writeline(wnd, " @ ", 1, 1, FALSE);
return TRUE;
case BORDER:
rtn = DefaultWndProc(wnd, msg, p1, p2);
writeline(wnd, "M", 2, 0, FALSE);
return rtn;
case MOUSE_MOVED:
SendMessage(wnd, HIDE_WINDOW, TRUE, 0);
SendMessage(wnd, MOVE, p1, p2);
SendMessage(wnd, SHOW_WINDOW, 0, 0);
return TRUE;
case CLOSE_WINDOW:
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
SendMessage(wnd, SHOW_MOUSE, 0, 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
WINDOW WatchIcon(void)
{
int mx, my;
WINDOW wnd;
SendMessage(NULL, CURRENT_MOUSE_CURSOR,
(PARAM) &mx, (PARAM) &my);
wnd = CreateWindow(
BOX,
NULL,
mx, my, 3, 5,
NULL,NULL,
WatchIconProc,
VISIBLE | HASBORDER | SHADOW | SAVESELF);
return wnd;
}